// Fill out your copyright notice in the Description page of Project Settings.


#include "Core/GameCore/TowerDefenceGameCamera.h"

#include "Camera/CameraComponent.h"
#include "Components/BoxComponent.h"
#include "GameFramework/SpringArmComponent.h"


ATowerDefenceGameCamera::ATowerDefenceGameCamera()
{
	PrimaryActorTick.bCanEverTick = false;
	CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("Boom"));
	MainCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("MainCamera"));
	MarkBox = CreateDefaultSubobject<UBoxComponent>("Sign");

	CameraBoom->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
	MainCamera->AttachToComponent(CameraBoom, FAttachmentTransformRules::KeepRelativeTransform);
	MarkBox->SetupAttachment(RootComponent);

	CameraBoom->TargetArmLength = 800.0f;
	CameraBoom->SetRelativeRotation(FRotator(-60.0f, 0.0f, 0.0f));

	// 设置碰撞预设
	MarkBox->SetCollisionProfileName(TEXT("ControllerPawnProfile"));
	// MarkBox->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
	// MarkBox->SetCollisionResponseToAllChannels(ECR_Ignore);
	// MarkBox->SetCollisionResponseToChannel(ECC_Visibility, ECR_Overlap);
	// MarkBox->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Overlap);

	CameraBoom->bDoCollisionTest = false;
}


void ATowerDefenceGameCamera::BeginPlay()
{
	Super::BeginPlay();
	
}




void ATowerDefenceGameCamera::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

}

void ATowerDefenceGameCamera::Zoom(float Direction, const float& ZoomSpeed)
{
	float Length = CameraBoom->TargetArmLength;
	Length += Direction * ZoomSpeed;
	Length = FMath::Clamp(Length, 400.0f, 800.0f);

	CameraBoom->TargetArmLength = Length;
}

